package ar.edu.caece.compiler.grammar;

import java.util.HashMap;
import java.util.Map;

import ar.edu.caece.compiler.grammar.attributes.Attribute;
import ar.edu.caece.compiler.model.Token;

public abstract class TokenRecognizer implements Recognizer {
	
	public abstract Recognizer execute(TokenVisitor visitor) throws Exception;
	
	private Map<String,Attribute> attributes;

	private Token token;
	
	public TokenRecognizer(Token token) {
		this();
		this.token = token;
	}

	public TokenRecognizer() {
		this.attributes = new HashMap<String,Attribute>();
	}

	public void setToken(Token token) {
		this.token = token;
	}

	public Token getToken() {
		return token;
	}

	public String getRepresentation() {
		return token.getSymbol().getRepresentation();
	}
	
	@Override
	public void addAttribute(String name, Attribute attribute) {
		this.attributes.put(name, attribute);
		
	}

	@Override
	public void clearAttributes() {
		this.attributes.clear();
	}

	@Override
	public Attribute getAttribute(String name) {
		return this.attributes.get(name);
	}
	
	@Override
	public Map<String,Attribute> getAttributes() {
		return this.attributes;
	}
	
	@Override
	public void setAttributes(Map<String,Attribute> attributes) {
		this.attributes = attributes;
	}
}
